package com.xian.ucenter.commons;

import lombok.Data;

import java.util.HashMap;
import java.util.Map;

@Data
public class Result {
    private Boolean success;
    private Integer code;
    private String message = "接口响应成功！";
    private Map<String,Object> data = new HashMap<>();

    private Result(Boolean success, Integer code) {
        this.success = success;
        this.code = code;
    }

    private Result(Boolean success, Integer code, String message) {
        this.success = success;
        this.code = code;
        this.message = message;
    }

    private Result(Boolean success, Integer code, Map<String,Object> map) {
        this.success = success;
        this.code = code;
        this.data = map;
    }

    private Result(Boolean success, Integer code, String message, Map<String,Object> map) {
        this.success = success;
        this.code = code;
        this.message = message;
        this.data = map;
    }

    public static Result ok() {
        return new Result(true,200);
    }
    public static Result ok(String message) {
        return new Result(true,200, message);
    }

    public static Result ok(Map<String,Object> map) {
        return new Result(true,200,map);
    }

    public static Result ok(String key,Object value) {
        Map<String, Object> map = new HashMap<>();
        map.put(key, value);
        return new Result(true,200,map);
    }

    public static Result ok(String message, String key, Object value) {
        Map<String, Object> map = new HashMap<>();
        map.put(key, value);
        return new Result(true,200,message,map);
    }

    public static Result fail() {
        return new Result(false,200,"接口响应失败！");
    }
    public static Result fail(String message) {
        return new Result(false,200,message);
    }

    public static Result fail(String message, String key, Object value) {
        Map<String, Object> map = new HashMap<>();
        map.put(key, value);
        return new Result(false,200,message,map);
    }

    public static Result fail(Map<String,Object> map) {
        return new Result(false,200,map);
    }

    public static Result fail(String key,Object value) {
        Map<String, Object> map = new HashMap<>();
        map.put(key, value);
        return new Result(true,200,map);
    }

    public static Result customerOk(Integer code, String message, String key, Object value) {
        Map<String, Object> map = new HashMap<>();
        map.put(key, value);
        return new Result(true,code,message,map);
    }

    public static Result customerOk(Integer code, String message, Map<String,Object> map) {
        return new Result(true,code,message,map);
    }

    public static Result customerFail(Integer code, String message, String key, Object value) {
        Map<String, Object> map = new HashMap<>();
        map.put(key, value);
        return new Result(false,code,message,map);
    }

    public static Result customerFail(Integer code, String message, Map<String,Object> map) {
        return new Result(false,200,map);
    }

    public static Result customerFail(Integer code, String message) {
        return new Result(false,code,message);
    }

    public Result data(String key,Object value) {
        this.data.put(key, value);
        return this;
    }

    public Object getData(String key) {
        return data.get(key);
    }
}
